import jwt
from datetime import datetime

from jwt import ExpiredSignatureError

from .settingg_manager import jwt_settings


class TokenManager:
    @classmethod
    def get_payload(cls, token):
        # 解析token成payload
        options = {'verify_exp': True}  # options中verify_exp为Ture，arch_jwt.decode会取出payload中的exp校验时间是否过期
        '''
        if "exp" in payload and options["verify_exp"]:
            self._validate_exp(payload, now, leeway)
        '''
        payload = jwt.decode(token, jwt_settings.SIGNING_KEY, algorithms=[jwt_settings.ALGORITHM], options=options)
        # {'token_type': 'access', 'exp': 1717146098, 'iat': 1717145798, 'jti': '29515b6efcd741399266c03fd72086c4', 'user_id': 1}
        return payload
